package cj.web.mall.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;

@DAO
public interface GoodsDAO {
	
	@SQL("select a.id,a.title,a.image,a.orignPriceRange,a.priceRange,MIN(i.orignPrice) as orignPrice, MIN(i.discntPrice) as discntPrice,count(i.id) as itmsCnt from SCGoods a JOIN SCSeller b on a.sellerId=b.id and b.deleteFlag=1 JOIN SCCategory c on a.categoryId=c.id and c.deleteFlag=1 JOIN SCGoodsItems i ON a.id=i.goodsId and i.deleteFlag=1  where a.deleteFlag=1 and a.status=1 GROUP BY a.id order by a.sellerId,a.stickAt desc")
	List<Map> goodsList();

	@SQL("select id,title,descs,image,orignPriceRange,priceRange from SCGoods where deleteFlag=1 and status=1 and id=:1")
	List<Map> getGoodsById(int id);

	@SQL("select id,sellerId,propValueNames,name,image,orignPrice,discntPrice from SCGoodsItems where deleteFlag=1 and goodsId=:1 ORDER BY stickAt desc")
	List<Map> getItemsByGoodsId(int id);
	
	@SQL("select id,sellerId,propValueNames,name,image,orignPrice,discntPrice from SCGoodsItems where deleteFlag=1 and goodsId=:1 and inventory>0 ORDER BY stickAt desc")
	List<Map> getVltItemsByGoodsId(int id);

	@SQL("select path from SCGoodsBanner where goodsId=:1")
	List<Map> getBannerByGoodsId(int id);

	@SQL("insert into SCCart(buyerId,sellerId,goodsItemId,count,status,deleteFlag,createUser,createAt,updateUser,updateAt) values (:1,:2,:3,:4,1,1,:5,NOW(),:5,NOW())")
	void insertCart(int buyerId, int sellerId, int goodsItemId, int count, String phone);

	@SQL("select id,sellerId,propValueNames,name,image,discntPrice,inventory,goodsId,type from SCGoodsItems where deleteFlag=1 and id=:1")
	List<Map> getGoodsItemById(int goodsItemId);

	@SQL("select name from SCSeller where deleteFlag=1 and id=:1")
	String getSellerName(int sellerId);

	@SQL("update SCCart set count=count + :1 where status=1 and deleteFlag=1 and buyerId=:2 and goodsItemId=:3")
	void updateCart(int count, int buyerId, int goodsItemId);

	@SQL("select count from SCCart where status=1 and deleteFlag=1 and buyerId=:1 and goodsItemId=:2")
	List<Map> isInCart(int buyerId, int goodsItemId);


}
